package com.stadium.servlet.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.stadium.bean.User;
import com.stadium.repository.UserRepository;
import com.stadium.servlet.UserServlet;

@Service(value = "UserServlet")
public class UserServletImpl implements UserServlet {
	
	@Autowired
	private UserRepository userRepository;

	//根据用户账号查找用户信息
	@Transactional(readOnly = true)
	public User getByAccount(String account) {
		return userRepository.getByAccount(account);
	}
	
	//保存用户信息
	@Transactional
	public void save(User user) {
		userRepository.saveAndFlush(user);
	}
	
	//返回所有用户信息
	@Transactional(readOnly = true)
	public List<User> getAllUsers(){
		return userRepository.findAll();
	}

	//根据id返回对应用户信息
	@Transactional(readOnly = true)
	public User getById(Integer id) {
		return userRepository.findOne(id);
	}

	//获取全部人员信息除超级管理员外
	@Transactional(readOnly = true)
	public List<User> getAll() {
		return userRepository.getAll();
	}
	
}
